import requests
import re


def get_address(addr_name='石门县新铺镇黄家峪村卫生室'):

    cookies = {
        '__yjs_duid': '1_3beb4a8c62ad03c6fdf94243f7e2c9531635595052995',
        'BIDUPSID': '148D33A835F07150E70E5BBE98627916',
        'PSTM': '1635686341',
        'BDUSS': 'FrRU5pVVJqNjNRbE1xM21ZcHdBRldZNFlTWHZmazFCaTRzOUZVOERadW9Tb2RqSVFBQUFBJCQAAAAAAAAAAAEAAADA9adwc29uYVRuVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKi9X2OovV9jUl',
        'BDUSS_BFESS': 'FrRU5pVVJqNjNRbE1xM21ZcHdBRldZNFlTWHZmazFCaTRzOUZVOERadW9Tb2RqSVFBQUFBJCQAAAAAAAAAAAEAAADA9adwc29uYVRuVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKi9X2OovV9jUl',
        'BAIDUID': '148D33A835F07150F9A36DE554047D4C:SL=0:NR=10:FG=1',
        'H_WISE_SIDS': '131862_132547_216840_213352_214801_110085_244723_261721_236312_262914_263347_256419_265883_266370_267298_267372_265615_259033_266714_268569_268592_268708_268031_265986_259642_269730_269781_269832_269904_270083_267066_256739_270460_270547_270917_271053_271021_270443_271169_271177_271075_269771_268987_269034_271227_267659_271323_265034_266027_270102_271883_270157_271673_269858_271812_269876_271957_271943_256151_271254_234295_234207_272226_270055_272280_272364_272008_272532_253022_272679_271689_272823_272816_272840_272959_260335_272469_269715_273016_267596_273063_267560_273091_273121_273140_273242_273301_273400_273398_271157_273532_273523_273519_273514_188331_272563_271562_271147_273703_264170_270186_263619_273165_273925_274082_273957_273965_274139_274155_274177_269609_273917_274238_273786',
        'BAIDUID_BFESS': '148D33A835F07150F9A36DE554047D4C:SL=0:NR=10:FG=1',
        '__bid_n': '18910b78e3892964b32a06',
        'BDRCVFR[Zh1eoDf3ZW3]': 'mk3SLVN4HKm',
        'delPer': '0',
        'PSINO': '3',
        'H_PS_PSSID': '26350',
        'BA_HECTOR': 'a4042ka0aga0alah8g24al2i1ihnpoq1p',
        'BDORZ': 'FFFB88E999055A3F8A630C64834BD6D0',
        'ZFY': 'OdCEtWKtzJZrztxpzMckrYRZexwE7SvguBsR0nnm3T4:C',
        'ab_sr': '1.0.1_ZjZiMGZiODc0Y2Y5NDc3MWExYjQxMzhjNGM4M2NjZjNkYzBhOGNkNTJlOWQwMWNlMjliZWU0YzNmZDA4NzcwN2FhNjgwYzVhNWU3YjI3Y2Q2MTlhMDhiNGUwMmY4MThkYzhmMjBlYzZlOWQxZmVkMjFhY2ZmNTZkZmMwNjQ2YmU1N2ZhMWFhNzVjODI0NDQ2MDljYTYxMmExZmNjNDI3NTEzZTA2ZDgwYjM2NGM5OTJhMzRjOWJlZTNlOTQ2MDAx',
        'H_WISE_SIDS_BFESS': '131862_132547_216840_213352_214801_110085_244723_261721_236312_262914_263347_256419_265883_266370_267298_267372_265615_259033_266714_268569_268592_268708_268031_265986_259642_269730_269781_269832_269904_270083_267066_256739_270460_270547_270917_271053_271021_270443_271169_271177_271075_269771_268987_269034_271227_267659_271323_265034_266027_270102_271883_270157_271673_269858_271812_269876_271957_271943_256151_271254_234295_234207_272226_270055_272280_272364_272008_272532_253022_272679_271689_272823_272816_272840_272959_260335_272469_269715_273016_267596_273063_267560_273091_273121_273140_273242_273301_273400_273398_271157_273532_273523_273519_273514_188331_272563_271562_271147_273703_264170_270186_263619_273165_273925_274082_273957_273965_274139_274155_274177_269609_273917_274238_273786',
    }

    headers = {
        'Referer': 'https://healthcare.hnybj.com.cn/',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.47',
    }

    response = requests.get(
        f'https://map.baidu.com/mobile/webapp/search/search/qt=s&wd={addr_name}/vt=map',
        cookies=cookies,
        headers=headers,
    )
    print('开始')
    try:
        poi_name = re.findall(r'<strong class="poi-name text-ellipsis">(.*?)</strong>', response.text, re.S)[0]
        address = re.findall(r'<div class="addr text-ellipsis">(.*?)</div>', response.text, re.S)[0]
    except:
        poi_name = ''
        address = ''

    return poi_name+','+address

